package com.prs.crm.action.official;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.official.DeptMailAutograph;
import com.prs.crm.service.official.DeptMailAutographService;

public class DeptMailAutographAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private PaginationSupport pagination;
	private DeptMailAutograph deptMailAutograph;
	private DeptMailAutographService deptMailAutographService;
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public DeptMailAutograph getDeptMailAutograph() {
		return deptMailAutograph;
	}
	public void setDeptMailAutograph(DeptMailAutograph deptMailAutograph) {
		this.deptMailAutograph = deptMailAutograph;
	}
	public DeptMailAutographService getDeptMailAutographService() {
		return deptMailAutographService;
	}
	public void setDeptMailAutographService(
			DeptMailAutographService deptMailAutographService) {
		this.deptMailAutographService = deptMailAutographService;
	}
	@Action("listDeptMailAutograph")
	public String listDeptMailAutograph(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(DeptMailAutograph.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getDeptMailAutographService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("editDeptMailAutograph")
	public String editDeptMailAutograph(){
		if (ids!=null) {
			this.deptMailAutograph=this.getDeptMailAutographService().get(ids[0]);
		}
		return SUCCESS;
	}
	@Action(value = "saveDeptMailAutograph", results = {
			@Result(name = "success", type = "redirect", location = "listDeptMailAutograph"),
			@Result(name = "error", type = "chain", location = "editDeptMailAutograph") })
	public String saveDeptMailAutograph(){
		if (deptMailAutograph.getId()==null) {
			this.getDeptMailAutographService().save(deptMailAutograph);
		}else{
			this.getDeptMailAutographService().submit(deptMailAutograph);
		}
		return SUCCESS;
	}
	@Action(value = "removeDeptMailAutograph", results = {
			@Result(name = "success", type = "redirect", location = "listDeptMailAutograph"),
			@Result(name = "error", type = "chain", location = "listDeptMailAutograph") })
	public String removeDeptMailAutograph(){
		if (ids!=null) {
			this.deptMailAutograph=this.getDeptMailAutographService().get(ids[0]);
		}
		this.getDeptMailAutographService().batchRemove(ids);
		return SUCCESS;
	}
}
